<?php
/**
* @package   auto_occasion
* @subpackage entreprise
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

class FoEntrepriseCtrl extends jController {
    /**
    * Page essai - front
    */
    function index() {

        global $gJCoord;

        jClasses::inc("entreprise~entrepriseSrv");
        jClasses::inc("commun~common");
        jClasses::inc ("commun~CNavBar") ;

        $rep = $this->getResponse('htmlFo');
        $rep->menusActifs = frontHtmlResponse::MENU_ENTREPRISE;
        $rep->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_ENTREPRISE) ;
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');


        //xml pour le header : title, desc, keywords
        $headerContent = common::readXml(PATH_XML_ESSAIS_ENTREPRISE);
        // change le header de la page en cours
        $rep->title						= isset($headerContent->title)?$headerContent->title:'';
		$headerContent->title			= isset($headerContent->title)?$headerContent->title:'' ;
		$headerContent->keywords		= isset($headerContent->keywords)? $headerContent->keywords:'' ;
		$headerContent->desc			= isset($headerContent->desc)? $headerContent->desc:'' ;
		$keywords						= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description					= "<meta name='Description' content='" . $headerContent->desc. "'>" ;
        $rep->addHeadContent($keywords);
        $rep->addHeadContent($description);
        // ---

        $iCurrentPage      = $gJCoord->request->getParam('iCurrentPage', 1);

        $typeId           = $this->intParam('type',0) ;
        $deptNum          = $this->intParam('cur',0) ;
        $deptId           = $this->intParam('dept',0) ;
        $villeNom         = $this->stringParam('ville',0);

        $type             = common::chargeParId($typeId, 'ao_type_entreprise');
        $region           = entrepriseSrv::getRegion($deptNum);
        $departementId    = entrepriseSrv::getIdRegion($region);
        $departement      = implode(',',$departementId);
        $deptNom = $ville = "";
        if ($iCurrentPage> 1) {
            $iDebutListe = ($iCurrentPage-1) * ENTREPRISE_NBITEMPARPAGE; 
        } else {
            $iDebutListe = 0 ;
        }
        if(($deptId) && (!$villeNom)){
            $entreprise    = entrepriseSrv::getAllEntrepriseByDept($typeId,$deptId, $iDebutListe, 20) ;
            $ville         = entrepriseSrv::getVille($deptId,$typeId);
            $deptNom       = common::chargeparId($deptId,'ao_departement');
        }elseif (($deptId) && ($villeNom)){
             $entreprise    = entrepriseSrv::getAllEntrepriseByVille($typeId,$deptId,$villeNom, $iDebutListe, 20) ;
        }else{
            $entreprise    = entrepriseSrv::getAllEntrepriseByType($typeId,$departement, $iDebutListe, 20);
        }
        
        // num surtaxé
        if (sizeof($entreprise)) {
            $entreprise['entreprise'] = entrepriseSrv::numSurtaxe($entreprise['entreprise']);
        }
        
        $oNavBar = new CNavBar (20, 5) ;
        $oNavBar->iCurrPage = $iCurrentPage;

        $oNavBar->normalizeBar ($entreprise['nbRecords']) ;
        $oNavBar->mergeBar ();

        if (!$deptNum) $region = "";
        $rep->bodyTpl = 'entreprise~FoEntreprise';
        $rep->body->assign('entreprise', $entreprise['entreprise']);
        $rep->body->assign('type', $type);
        $rep->body->assign('region', $region);
        $rep->body->assign('nb', $entreprise['nbRecords']);
        $rep->body->assign("oNavBar", $oNavBar);
        $rep->body->assign("deptNom", $deptNom);
        $rep->body->assign("ville", $villeNom);
        $rep->body->assign("deptNum", $deptNum);
        $rep->body->assign("dpt", $deptId);


        $rep->body->assignZone('oZoneMarquePopulaire', 'accueil~FoHomeMarquePopulaire');
        
        //pubHidden et rightContent
        $paramPub = array('p1'=>PUB_RIGHT_1_ID,'p2'=>PUB_RIGHT_2_ID,'p3'=>PUB_RIGHT_3_ID,'p4'=>PUB_RIGHT_4_ID,'p5'=>PUB_RIGHT_5_ID,'p6'=>PUB_RIGHT_6_ID);
        $rep->body->assignZone('oZonePubHidden', 'commun~FoPubHidden',$paramPub);
        

        $rep->body->assignZone('oZoneRightContent', 'commun~FoRightContent');
        $rep->body->assignZone('oZoneEntrepriseHeader', 'entreprise~FoEntrepriseHeader');
        $rep->body->assignZone('oZoneEntrepriseRestrict', 'entreprise~FoEntrepriseRestrict',array('region'=>$region,'type'=>$type,'departement'=>$departement,'deptId'=>$deptId,'deptNum'=>$deptNum,'ville'=>$ville, 'villeNom'=>$villeNom));


        return $rep;
    }

    function entreprise() {

        global $gJCoord;

        jClasses::inc("entreprise~entrepriseSrv");
        jClasses::inc("commun~common");
        jClasses::inc ("commun~CNavBar") ;

        $rep = $this->getResponse('htmlFo');
        //xml pour le header : title, desc, keywords
        $headerContent = common::readXml(PATH_XML_ESSAIS_ENTREPRISE2); 
        // change le header de la page en cours
        $rep->title					=	isset($headerContent->title)?$headerContent->title:'' ;
		$headerContent->keywords	=	isset($headerContent->keywords)?$headerContent->keywords:'' ;
		$headerContent->desc		=	isset($headerContent->desc)?$headerContent->desc:'' ;
		$keywords					= "<meta name='keywords' content='" . $headerContent->keywords . "'>" ;
		$description				= "<meta name='Description' content='" . $headerContent->desc. "'>" ;
        $rep->addHeadContent($keywords);
        $rep->addHeadContent($description);
        // ---
        $rep->menusActifs = frontHtmlResponse::MENU_ENTREPRISE;
        $rep->breadCrumb  = array(frontHtmlResponse::MENU_ACCUEIL, frontHtmlResponse::MENU_ENTREPRISE) ;
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/front/js/pub.js');

        $iCurrentPage      = $gJCoord->request->getParam('iCurrentPage', 1);

        $typeId           = $this->intParam('type',0) ;
        $deptNum          = $this->intParam('cur',0) ;
        $deptId           = $this->intParam('dept',0) ;
        $villeNom         = $this->stringParam('ville',0);

        $type             = common::chargeParId($typeId, 'ao_type_entreprise');
        $region           = entrepriseSrv::getRegion($deptNum);
        $departementId    = entrepriseSrv::getIdRegion($region);
        $departement      = implode(',',$departementId);
        $deptNom = $ville = "";
		
        if ($iCurrentPage> 1){
            $iDebutListe = ($iCurrentPage-1) * ENTREPRISE_NBITEMPARPAGE; 
        }else{
            $iDebutListe = 0 ;
        }
        if(($deptId) && (!$villeNom)){
			
            $entreprise    = entrepriseSrv::getAllEntrepriseByDept($typeId,$deptId, $iDebutListe, 20) ;
            $ville         = entrepriseSrv::getVille($deptId,$typeId);
            $deptNom       = common::chargeparId($deptId,'ao_departement');
        }elseif (($deptId) && ($villeNom)){
			
             $entreprise    = entrepriseSrv::getAllEntrepriseByVille($typeId,$deptId,$villeNom, $iDebutListe, 20) ;
        }else{
            $entreprise    = entrepriseSrv::getAllEntrepriseByType($typeId,$departement, $iDebutListe, 20);
        }

		if ( $typeId==1) {
			foreach ($entreprise['entreprise'] as $oItem) {
				$oItem->zNumeroSurTaxe	= entrepriseSrv::getNumSurtaxe($oItem) ;
				$oItem->iTypeId			= $typeId ;
			}
		}
        $oNavBar = new CNavBar (20, 5) ;
        $oNavBar->iCurrPage = $iCurrentPage;

        $oNavBar->normalizeBar ($entreprise['nbRecords']) ;
        $oNavBar->mergeBar ();


        $rep->bodyTpl = 'entreprise~FoEntrepriseAutre';
        $rep->body->assign('entreprise', $entreprise['entreprise']);
        $rep->body->assign('type', $type);
        $rep->body->assign('region', $region);
        $rep->body->assign('nb', $entreprise['nbRecords']);
        $rep->body->assign("oNavBar", $oNavBar);
        $rep->body->assign("deptNom", $deptNom);
        $rep->body->assign("ville", $villeNom);
        $rep->body->assign("deptNum", $deptNum);
        $rep->body->assign("dpt", $deptId);


        $rep->body->assignZone('oZoneMarquePopulaire', 'accueil~FoHomeMarquePopulaire');
        $rep->body->assignZone('oZoneEntrepriseRight', 'entreprise~FoEntrepriseRight',array('entreprises'=>serialize($entreprise)));
        $rep->body->assignZone('oZoneEntrepriseHeader', 'entreprise~FoEntrepriseHeader');
        $rep->body->assignZone('oZoneEntrepriseRestrict', 'entreprise~FoEntrepriseRestrict',array('region'=>$region,'type'=>$type,'departement'=>$departement,'deptId'=>$deptId,'deptNum'=>$deptNum,'ville'=>$ville, 'villeNom'=>$villeNom));


        return $rep;
    }

}